package com.yanqu.road.server.pb;

import com.yanqu.road.entity.config.goods.GoodsBagInfo;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.pb.common.CommonProto;
import com.yanqu.road.server.manger.ServerLanguageMgr;
import com.yanqu.road.utils.string.StringUtils;

import java.util.List;

public class CommonPb {
    public static CommonProto.GoodsTempMsg.Builder parseGoodsTempMsg(GoodsInfo goodsInfo, String language){
        if(null == goodsInfo){
            return null;
        }
        CommonProto.GoodsTempMsg.Builder msg = CommonProto.GoodsTempMsg.newBuilder();
        msg.setGoodsId(goodsInfo.getGoodsId());
        msg.setName(ServerLanguageMgr.getContent(goodsInfo.getGoodsName(), language));
        msg.setDesc(ServerLanguageMgr.getContent(goodsInfo.getGoodsDesc(), language));
        msg.setType(goodsInfo.getType());
        msg.setIcon(goodsInfo.getIcon());
        msg.setSort(goodsInfo.getSort());
        msg.setQuality(goodsInfo.getQuality());
        msg.setCanUse(goodsInfo.getCanUse());
        msg.setUseMax(goodsInfo.getTopLimit());
        msg.setGetWay(goodsInfo.getGetWay());
        msg.setParam(goodsInfo.getParamStr());
        msg.setExtendParam(goodsInfo.getExtendParam());
        msg.setResourceParam(goodsInfo.getResourceParam());
        msg.setHidden(goodsInfo.isHidden());
        msg.setCanBagUse(goodsInfo.isCanBagUse());
        msg.setNote(ServerLanguageMgr.getContent(goodsInfo.getGoodsName() + "_abc", language));
        msg.setRecyclingType(goodsInfo.getRecyclingType());
        return msg;
    }

    public static CommonProto.GoodsListMsg.Builder parseGoodsListMsg(List<GoodsInfo> goodsInfoList, String language, List<GoodsBagInfo> goodsBagInfoList){
        CommonProto.GoodsListMsg.Builder listMsg = CommonProto.GoodsListMsg.newBuilder();
        if(null != goodsInfoList){
            for(GoodsInfo goodsInfo : goodsInfoList){
                CommonProto.GoodsTempMsg.Builder msg = parseGoodsTempMsg(goodsInfo, language);
                if(null != msg){
                    listMsg.addDataList(msg);
                }
            }
            for (GoodsBagInfo goodsBagInfo : goodsBagInfoList) {
                CommonProto.GoodsBagTempMsg.Builder goodsBagTempMsg = parseGoodsBagTempMsg(goodsBagInfo);
                listMsg.addBagList(goodsBagTempMsg);
            }
        }
        return listMsg;
    }

    private static CommonProto.GoodsBagTempMsg.Builder parseGoodsBagTempMsg(GoodsBagInfo goodsBagInfo) {
        CommonProto.GoodsBagTempMsg.Builder goodsBagTempMsg = CommonProto.GoodsBagTempMsg.newBuilder();
        goodsBagTempMsg.setId(goodsBagInfo.getId());
        goodsBagTempMsg.setBagId(goodsBagInfo.getBagId());
        goodsBagTempMsg.setItemId(goodsBagInfo.getGoodsId());
        goodsBagTempMsg.setMinNum(goodsBagInfo.getMinNum());
        goodsBagTempMsg.setMaxNum(goodsBagInfo.getMaxNum());
        goodsBagTempMsg.setRandomType(goodsBagInfo.getRandomType());
        goodsBagTempMsg.setProbability(goodsBagInfo.getRandomWeight());
        return goodsBagTempMsg;
    }

    public static CommonProto.MallTempMsg.Builder parseMallTempMsg(MallInfo mallInfo, String language){
        if(null == mallInfo){
            return null;
        }
        CommonProto.MallTempMsg.Builder msg = CommonProto.MallTempMsg.newBuilder();
        msg.setMallId(mallInfo.getMallId());
        msg.setMallName(ServerLanguageMgr.getContent(mallInfo.getMallName(), language));
        msg.setShopType(mallInfo.getShopType());
        msg.setReward(mallInfo.getReward());
        msg.setCategory(mallInfo.getCategory());
        msg.setPrice(mallInfo.getPrice());
        msg.setOldPrice(mallInfo.getOldPrice());
        msg.setPriceAdd(mallInfo.getPriceAdd());
        int isDouble = 0;
        if(mallInfo.isFirstDouble()){
            isDouble = 1;
        }
        msg.setIsDouble(isDouble);
        msg.setBuyLimitType(mallInfo.getLimitBuyType());
        msg.setBuyLimit(mallInfo.getLimitBuyCount());
        msg.setSort(mallInfo.getSort());
        msg.setParam(mallInfo.getParam());
        msg.setPointSign(mallInfo.getPointSign());
        int isShow = 0;
        if(mallInfo.isShow()){
            isShow = 1;
        }
        msg.setIsShow(isShow);
        msg.setRechargeId(mallInfo.getRechargeId());
        msg.setActivityId(mallInfo.getActivityId());
        msg.setExtendParam(mallInfo.getExtendParam());
        msg.setVipLimit(mallInfo.getVipLimit());
        msg.setShopId(mallInfo.getShopId());
        msg.setBuyLimitParam(mallInfo.getBuyLimitParam());
        msg.addAllSystemLimit(mallInfo.getSystemLimit());
        if (!StringUtils.isNullOrEmpty(mallInfo.getCanBuyParam())) {
            msg.setCanBuyParam(mallInfo.getCanBuyParam());
        }
        msg.setReSetTime(mallInfo.getReSetTime());
        msg.setNeedRemind(mallInfo.getNeedRemind());
        msg.setDiscount(mallInfo.getDiscount());
        msg.setIsSpecial(mallInfo.getIsSpecial());
        msg.setCostPerformance(mallInfo.getCostPerformance());
        return msg;
    }
}
